Many computer graphic images are created by mathematically modeling the interaction of light with a three-dimensional (3D) scene from a given viewpoint. This process, called “rendering,” generates a two-dimensional (2D) image of the scene from the given viewpoint, and is analogous to taking a photograph of a real-world scene.
As the demand for computer graphics, and in particular for real-time computer graphics, has increased, computer systems with graphics processing subsystems adapted to accelerate the rendering process have become widespread. In these computer systems, the rendering process is often described as a “graphics pipeline” and is divided between a computer's general purpose central processing unit (CPU) and the graphics processing subsystem, architecturally centered about a graphics processing unit (GPU). Typically, the CPU performs high-level operations, such as determining the position, motion, and collision of objects in a given scene. From these high-level operations, the CPU generates a set of rendering commands and data defining the desired rendered image or images. For example, rendering commands and data can define scene geometry, lighting, shading, texturing, motion, and/or camera parameters for a scene. The graphics processing subsystem creates one or more rendered images from the set of rendering commands and data.
Scene geometry is typically represented by geometric primitives, such as points, lines, polygons (for example, triangles and quadrilaterals), and curved surfaces, defined by one or more two- or three-dimensional vertices. Each vertex may have additional scalar or vector attributes used to determine qualities such as the color, transparency, lighting, shading, and animation of the vertex and its associated geometric primitives. Scene geometry may also be approximated by a depth texture representing view-space Z coordinates of opaque objects covering each pixel.
Many graphics processing subsystems are highly programmable through an application programming interface (API), enabling complicated lighting and shading algorithms, among other things, to be implemented. To exploit this programmability, applications can include one or more graphics processing subsystem programs, which are executed by the graphics processing subsystem in parallel with a main program executed by the CPU. Although not confined merely to implementing shading and lighting algorithms, these graphics processing subsystem programs are often referred to as “shading programs,” “programmable shaders,” or simply “shaders.”
Pixel shaders are one example of shading programs. Pixel shaders are used in a technique known as “deferred shading” in which various lighting and shading processes are decoupled from, and carried out after, geometry rendering in a later stage of the graphics pipeline known as “screen-space.” Screen-space rendering occurs just before displaying a scene, and screen-space rendering processes are carried out pixel-by-pixel. Deferred shading is a technique employed by many modern rendering engines that allows rendering of numerous complex geometries and light sources while simplifying the graphics pipeline and maintaining a proportional relationship between quality and performance.
One limitation of screen-space techniques such as deferred shading is the lack of data available at later stages of the graphics pipeline. Screen-space rendering processes rely on data available in a geometry buffer, or “G-buffer.” The G-buffer is generated during geometry rendering and rasterizing. The G-buffer stores material properties of all visible geometry per-pixel. A specific limitation of deferred shading is the inability to resolve shading ambiguities in screen-space. This is otherwise referred to as an incompatibility with anti-aliasing, or “AA.”
Aliasing in computer graphics occurs when a high-resolution, or “high-frequency,” image feature is reproduced at a low-resolution. High-resolution features most occur at boundaries between two or more surfaces in an image. The rendering process is unable to distinguish the boundaries, causing them to become distorted. Shading ambiguities may be resolved during rendering by traditional multisampling AA techniques. However, once the surface boundaries are rasterized to a pixel, ambiguities may remain with respect to how the pixel is to be shaded. This is due to the fact that, in screen-space, the G-buffer lacks sufficient geometric pixel coverage data to perform AA.
Shading during geometry rendering provides other benefits over deferred shading. For example, deferred shading is largely incapable of handling transparency in surfaces. Deferred shading also requires a larger G-buffer so complex compositions of materials in a scene may be shaded appropriately. These disadvantages, together with the incompatibility of AA, sometimes lead graphics developers to avoid deferred shading all-together.